using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class SliderToggerNode : MonoBehaviour
{
    [SerializeField]
    Toggle toggle;
    public Toggle Toggle => toggle;
    [SerializeField]
    Image swichImage;
    [SerializeField]
    Vector3 onPos, offPos;
    public void Awake()
    {
        if (toggle == null)
        {
            toggle = GetComponent<Toggle>();    
        }
        toggle.onValueChanged.AddListener(OnToggle);
        OnToggle(toggle.isOn);
    }

    public void SetToggleState(bool isOn)
    {
        toggle.isOn = isOn;
        OnToggle(isOn);
    }

    void OnToggle(bool isOn)
    {
        if (isOn)
        {
            //turn on the node
            swichImage.rectTransform.DOAnchorPos3D(onPos, 0.5f);
        }
        else
        {
            //turn off the node
            swichImage.rectTransform.DOAnchorPos3D(offPos, 0.5f);
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
